#include "Vector.h"
#define _USE_MATH_DEFINES
#include <math.h>

Vector::Vector(void)
{
}

Vector::Vector(float x, float y, float z)
{
	m_x = x;
	m_y = y;
	m_z = z;
}

Vector::~Vector(void)
{
}

void	Vector::Set(float x, float y)
{
	m_x = x;
	m_y = y;
}

float	Vector::GetX() const
{
	return m_x;
}

float	Vector::GetY() const
{
	return m_y;
}

float	Vector::GetZ() const
{
	return m_z;
}

Vector	Vector::add(const Vector &vec) const
{
	return Vector(m_x + vec.GetX(), m_y + vec.GetY(), m_z + vec.GetZ());
}

Vector	Vector::subtract(const Vector &vec) const
{
	return Vector(m_x - vec.GetX(), m_y - vec.GetY(), m_z - vec.GetZ());
}

Vector	Vector::mult(float n) const
{
	return Vector(m_x*n, m_y*n, m_z*n);
}

Vector	Vector::divide(float n) const
{
	return Vector(m_x/n, m_y/n, m_z/n);
}

float	Vector::dot(const Vector &vec) const
{
	return m_x*vec.GetX() + m_y*vec.GetY() + m_z*vec.GetZ();
}

Vector	Vector::cross(const Vector& vec) const
{
	return Vector(	 m_y*vec.GetZ() - m_z*vec.GetY(),
					-m_x*vec.GetZ() + m_z*vec.GetX(),
					 m_x*vec.GetY() - m_y*vec.GetX() );
}

float	Vector::length() const
{
	return sqrt(m_x*m_x + m_y*m_y+m_z*m_z);
}

float	Vector::distance(const Vector &vec) const
{
	return subtract(vec).length();
}

Vector	Vector::normalise()
{
	float len = length();
	Set(m_x/len, m_y/len);
	return *this;
}


Vector	operator+ (const Vector &lhs, const Vector &rhs)
{
	return lhs.add(rhs);
}

Vector	operator- (const Vector &lhs, const Vector &rhs)
{
	return lhs.subtract(rhs);
}

Vector	operator* (const Vector &lhs, float n)
{
	return lhs.mult(n);
}

Vector	operator* (float n, const Vector &rhs)
{
	return rhs.mult(n);
}

Vector	operator/ (const Vector &lhs, float n)
{
	return lhs.divide(n);
}